//
//  YBAssetsDetailResultViewController.m
//  Nectar
//
//  Created by famer on 2023/11/12.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBAssetsDetailResultViewController+LayoutConstraints.h"

@interface YBAssetsDetailResultViewController ()

@end

@implementation YBAssetsDetailResultViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = kWhiteColor;
    
    [self.view addSubview:self.navigationBar];
    [self.view addSubview:self.contentView];
    [self.contentView addSubview:self.statusImageView];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.dateLabel];

    [self.contentView addSubview:self.detailContentView];
    [self.detailContentView addSubview:self.detailLabel];
    [self.detailContentView addSubview:self.receiveLabel];
    [self.detailContentView addSubview:self.receiveAmountLabel];
    [self.detailContentView addSubview:self.receiveTipsLabel];
    [self.detailContentView addSubview:self.receiveTipsImageView];
    
    [self.contentView addSubview:self.transferContentView];
    [self.transferContentView addSubview:self.fromLabel];
    [self.transferContentView addSubview:self.fromValueLabel];
    [self.transferContentView addSubview:self.toLabel];
    [self.transferContentView addSubview:self.toValueLabel];

    [self.contentView addSubview:self.txidContentView];
    [self.txidContentView addSubview:self.txidLabel];
    [self.txidContentView addSubview:self.txidValueLabel];

    [self updateUI];
    [self setLayoutConstraints];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self.navigationBar resetBarItemState];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}

#pragma mark - Private Method
- (void)updateUI{
    self.dateLabel.text = self.data.createTime;
    self.txidValueLabel.text = self.data.txid;
    self.receiveTipsLabel.text = self.data.symbol;
    
    if([self.data.status containsString:@"fail"]){
        self.statusLabel.text = @"Failure";
        self.statusLabel.textColor = [UIColor hexColor:@"FF575C"];
        self.statusImageView.image = [UIImage imageNamed:@"icon_failure"];
        self.receiveTipsImageView.image = [UIImage imageNamed:@"icon_failure"];
        
    } else if([self.data.status containsString:@"succe"]){
        self.statusLabel.text = @"Successful";
        self.statusLabel.textColor = [UIColor hexColor:@"65CA79"];
        self.statusImageView.image = [UIImage imageNamed:@"icon_success"];
        self.receiveTipsImageView.image = [UIImage imageNamed:@"icon_success"];
        
    } else if([self.data.status containsString:@"process"]){
        self.statusLabel.text = @"Processing";
        self.statusLabel.textColor = [UIColor hexColor:@"65CA79"];
        self.statusImageView.image = [UIImage imageNamed:@"icon_processing"];
        self.receiveTipsImageView.image = [UIImage imageNamed:@"icon_processing"];
        
    } else if([self.data.status containsString:@"create"]){
        self.statusLabel.text = @"Processing";
        self.statusLabel.textColor = [UIColor hexColor:@"65CA79"];
        self.statusImageView.image = [UIImage imageNamed:@"icon_processing"];
        self.receiveTipsImageView.image = [UIImage imageNamed:@"icon_processing"];
    }

    if([self.data.inOrOut containsString:@"out"]){
        self.receiveLabel.text = @"Out";
        self.receiveAmountLabel.text = [NSString stringWithFormat:@"- %@", self.data.amount];
        self.toValueLabel.text = self.data.address;
        self.fromLabel.hidden = YES;
        self.fromValueLabel.hidden = YES;
    
    } else {
        self.receiveLabel.text = @"Receive";
        self.receiveAmountLabel.text = [NSString stringWithFormat:@"+ %@", self.data.amount];
        self.fromValueLabel.text = self.data.address;
        self.toLabel.hidden = YES;
        self.toValueLabel.hidden = YES;
    }
}

#pragma mark - Getter Setter
YBViewGetter(contentView, _contentView, kThemeBackground);
YBViewGetter(detailContentView, _detailContentView, kWhiteColor);
YBViewGetter(transferContentView, _transferContentView, kWhiteColor);
YBViewGetter(txidContentView, _txidContentView, kWhiteColor);

YBImageViewGetter(statusImageView, _statusImageView, [UIImage imageNamed:@"icon_success"]);

YBImageViewGetter(receiveTipsImageView, _receiveTipsImageView, [UIImage imageNamed:@"icon_success"]);

YBLabelGetter(statusLabel, _statusLabel, [UIFont systemFontOfSize:14], @"Successful", [UIColor hexColor:@"65CA79"], NSTextAlignmentCenter);

YBLabelGetter(dateLabel, _dateLabel, [UIFont systemFontOfSize:12], @"*", [UIColor hexColor:@"84828C"], NSTextAlignmentCenter);

YBLabelGetter(detailLabel, _detailLabel, [UIFont systemFontOfSize:12], @"Details", kThemeHintColor, NSTextAlignmentLeft);

YBLabelGetter(receiveLabel, _receiveLabel, [UIFont systemFontOfSize:12], @"*", kThemeBlackColor, NSTextAlignmentLeft);

YBLabelGetter(receiveAmountLabel, _receiveAmountLabel, [UIFont systemFontOfSize:12], @"*", kThemeBlackColor, NSTextAlignmentLeft);

YBLabelGetter(receiveTipsLabel, _receiveTipsLabel, [UIFont systemFontOfSize:12], @"*", kThemeHintColor, NSTextAlignmentLeft);

YBLabelGetter(fromLabel, _fromLabel, [UIFont systemFontOfSize:12], @"From", kThemeHintColor, NSTextAlignmentLeft);

YBLabelGetter(fromValueLabel, _fromValueLabel, [UIFont systemFontOfSize:12], @"*", kThemeBlackColor, NSTextAlignmentLeft);

YBLabelGetter(toLabel, _toLabel, [UIFont systemFontOfSize:12], @"To", kThemeHintColor, NSTextAlignmentLeft);

YBLabelGetter(toValueLabel, _toValueLabel, [UIFont systemFontOfSize:12], @"*", kThemeBlackColor, NSTextAlignmentLeft);

YBLabelGetter(txidLabel, _txidLabel, [UIFont systemFontOfSize:12], @"TxID", kThemeHintColor, NSTextAlignmentLeft);

YBLabelGetter(txidValueLabel, _txidValueLabel, [UIFont systemFontOfSize:12], @"*", kThemeBlackColor, NSTextAlignmentLeft);


- (YBNavigationBar *)navigationBar{
    if(!_navigationBar){
        _navigationBar = [[YBNavigationBar alloc] initWithFrame:CGRectZero];
        _navigationBar.backgroundColor = kWhiteColor;
        [_navigationBar setTitle:@"Details" titleColor:kThemeBlackColor];
        [_navigationBar setLeftBarImage:@"icon_nav_back" forState:UIControlStateNormal];
        __weak __typeof(&*self)weakSelf = self;
        _navigationBar.onLeftBarButtonBlock = ^(){
            __strong __typeof(&*weakSelf)strongSelf = weakSelf;
            if(!strongSelf) return;
            
            [strongSelf.navigationController popViewControllerAnimated:YES];
        };
    }
    return _navigationBar;
}

@end
